package com.oms.servlet;

import com.liudecai.utils.servlet.BaseServlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class HomeNavServlet
 */
@WebServlet("/HomeNavServlet")
public class HomeNavServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * Default constructor.
	 */
	public HomeNavServlet() {
		// TODO Auto-generated constructor stub
	}

	public String ToView(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String toview = request.getParameter("view");
		System.out.println(toview);

		if ("index".equals(toview)) {
			return "r:/home/index.jsp";
		} else if ("mycart".equals(toview)) {
			return "r:/home/myCart.jsp";
		} else if ("order".equals(toview)) {
			return "r:/home/order_2.jsp";
		} else if ("usercenter".equals(toview)) {
			return "r:/home/user.jsp";
		} else if ("senddescription".equals(toview)) {
			return "r:/home/DC.jsp";
		} else if ("aboutus".equals(toview)) {
			return "r:/home/aboutUs.jsp";
		} else if ("loginout".equals(toview)) {
			loginout(request, response);
		} else {
			return "无效的菜单";
		}
		return toview;
	}

	public String loginout(HttpServletRequest request, HttpServletResponse response) throws IOException {
		System.out.println(request.getContextPath() + "/HomeNavServlet?method=ToView&view=index");
//		request.getSession().invalidate();
		response.setHeader("Refresh", "2;URL=" + request.getContextPath() + "/home/");
		response.getWriter().println("退出成功!2秒后跳转!");
		return null;
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
